<template>
  <div class="login">
    <div class="loginBg">
      <img src="../assets/image/loginBg.png" alt="">
    </div>
    <div class="inputBox" >
    <div class="inputBox">
      <div class="userPassword userInput">
        <i class="iconfont icon-shenfenzheng3"></i>
        <input  type="text" placeholder="请输入身份证号码或姓名" v-model="userName">
      </div>
      <div class="userName userInput" >
        <i class="iconfont icon-icon-test"></i>
        <input type="text" placeholder="请输入手机号" v-model="userPass">
      </div>
    </div>
    </div>
    <div class="loginBtnBox">
      <div @click="goHello" class="loginBtn">登&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;录</div>
      <div @click="goHelloPin" class="loginBtn">核&nbsp;销&nbsp;登&nbsp;录</div>
      <!--<div @click="goBack" class="backBtn">返&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;回</div>-->
<!--      <router-link to="/regist"><div class="register">学员注册</div></router-link>-->
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import * as exampleApi from 'api/example'
  export default {
    name: 'login',
    components: {},
    data () {
      return {
        data: {},
        siteId: '',
        studentId: '',
        openId: '',
        userName: '',
        userPass: ''
      }
    },
    mounted () {
      this.openId = window.sessionStorage.getItem('openId')
      this.siteId = window.sessionStorage.getItem('siteId')
      this._initData()
    },
    methods: {
      _initData() {
        exampleApi.modePost('/api/public/sys/setting/getByOrgId', {
          orgId: this.siteId
        }).then(
          res => {
            this.data = res.data.data
          }
        )
      },
      goHello () {
        var tel = /^[1][3,4,5,7,8][0-9]{9}$/
        if (this.userPass === '') {
          alert('请输入手机号码！')
        } else if (!tel.test(this.userPass)) {
          alert('请输入正确的手机号码！')
        } else if (this.userName === '') {
          alert('请输入身份证号码或姓名！')
        } else {
          exampleApi.modeGet('/api/public/sys/user/login?username=' + this.userName +
            '&password=' + this.userPass +
            '&orgId=' + this.siteId +
            '&loginKind=student' +
            '&openId=' + this.openId).then(res => {
            console.log(res)
            if (res.data.code === '0') {
              this.studentId = res.data.data.humanId
              window.sessionStorage.setItem('studentId', res.data.data.optUser.id)
              window.sessionStorage.setItem('studentName', res.data.data.optUser.name)
              window.sessionStorage.setItem('mobile', res.data.data.optUser.mobile)
              window.sessionStorage.setItem('userType', '0')
              this.$router.push({path: '/personal'})
            } else {
              alert(res.data.msg)
            }
          })
        }
      },
      goBack () {
        window.history.go(-1)
      },
      goHelloPin () {
        var tel = /^[1][3,4,5,7,8][0-9]{9}$/
        if (this.userPass === '') {
          alert('请输入手机号码！')
        } else if (!tel.test(this.userPass)) {
          alert('请输入正确的手机号码！')
        } else if (this.userName === '') {
          alert('请输入姓名')
        } else {
          exampleApi.modeGet('/api/public/sys/user/pinLogin?username=' + this.userName +
            '&password=' + this.userPass +
            '&orgId=' + this.siteId).then(res => {
            if (res.data.code === '0') {
              this.studentId = res.data.data.humanId
              window.sessionStorage.setItem('studentId', res.data.data.humanId)
              window.sessionStorage.setItem('studentName', res.data.data.studName)
              window.sessionStorage.setItem('mobile', res.data.data.mobile)
              window.sessionStorage.setItem('userType', '1')
              this.$router.push({path: '/personal'})
            } else {
              alert(res.data.msg)
            }
          })
        }
      }
    }
  }
</script>

<style lang="less" scoped>
  .login {
    .loginBg {
      width: 100%;
        img {
          width: 100%;
      }
  }
    .inputBox {
      .userInput {
        width: 90%;
        height: 50px;
        margin: 20px auto;
        border-radius: 20px;
        border: 2px solid #d6d6d6;
        line-height: 60px;
          input::-webkit-input-placeholder {
            color: #dfdfdf;
          }
          input {
            width: 80%;
            height: 30px;
            border: none;
            font-size: 25px;
            margin-left: 3%;
            margin-bottom: 3px;
            color: #999999;
          }
          i {
            vertical-align: middle;
            font-size: 18px;
            color: #e9e9e9;
          }
        }
    .userName {
    }
    .userPassword {
    }
    .forgetPassword {
      font-size: 16px;
      color: #dfdfdf;
      width: 90%;
      margin: 0px auto;
      text-align: right;
      padding-right: 20px;
    }
  }
  .loginBtnBox {
  .loginBtn {
    width: 90%;
    height: 60px;
    text-align: center;
    color: #ffffff;
    font-size: 30px;
    background-color: #2f82ff;
    border-radius: 20px;
    margin: 16px auto 20px;
    line-height: 60px;
  }
  .backBtn {
    width: 90%;
    height: 40px;
    text-align: center;
    color: #ffffff;
    font-size: 18px;
    background-color: #179e47;
    border-radius: 20px;
    margin: 9px auto 20px;
    line-height: 40px;
  }
  .register {
    text-align: center;
    font-size: 16px;
    color: #2f82ff;
    font-weight: bold;
  }
  a {
    text-decoration: none;
    outline: none;
  }
  a:hover{
    text-decoration: none;
    outline: none;
  }
  }
  }
</style>
